#include<bits/stdc++.h>
#define ll long long
#define R register
using namespace std;
const int N=1e3+5;
struct Line{ll l,r;}a[N];
int q;ll mn[N],mx[N],num;
set<ll> s1;
inline void calc(){
	ll res=0;
	vector<ll> v1,v2;
	auto it=s1.begin();
	while(it!=s1.end()){
		v1.emplace_back((*it));v2.emplace_back((*it));
		it=s1.upper_bound((*it));
	}
	sort(v2.begin(),v2.end(),[&](ll x,ll y){return x>y;});
	int ln=v1.size();ll sum1=0,sum2=0;
	for(R int i=0;i<ln;++i){
		sum1+=v1[i];sum2+=v2[i];
		mn[i+1]=sum1,mx[i+1]=sum2;
	}
	int tot=0;
	for(R int i=1;i<=ln;++i){
		if(mn[i]<mx[i]){
			a[++tot]={mn[i],mx[i]-1};
		}
	}
	if(!tot)return cout<<"0\n",void();
	sort(a+1,a+tot+1,[&](Line x,Line y){return (x.r!=y.r?x.r<y.r:x.l<y.l);});
	ll sum=a[1].r-a[1].l+1;
	for(R int i=2;i<=tot;++i){
		sum+=(a[i].r-a[i].l+1)-max(a[i-1].r-a[i].l+1,0ll);
	}
	cout<<sum<<'\n';
}
int blk=0;
int main(){
	freopen("kte.in","r",stdin);
	freopen("kte.out","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
	cin>>q;
	if(q<=1000){
		while(q--){
			ll x;cin>>x;
			++blk;
			if(s1.find(x)!=s1.end())s1.erase(x),num-=x;
			else s1.insert(x),num+=x;
			calc();
		}
	}else{
		while(q--){
			ll x;cin>>x;
			++blk;
			if(s1.find(x)!=s1.end())s1.erase(x),num-=x;
			else s1.insert(x),num+=x;
			if(blk<=500){
				calc();
			}else{
				ll l=(*s1.begin()),r=num-(*s1.begin())-1;
				cout<<r-l+1<<'\n';
			}
		}
	}
	return 0;
}
